﻿using System;
using System.Drawing;
using System.Windows.Forms;
using Finance.Data;

namespace Finance.Views
{
	public partial class NoteListItemView : UserControl
	{
		public NoteListItemView()
		{
			InitializeComponent();
		}

		public override ContextMenu ContextMenu
		{
			get
			{
				return base.ContextMenu;
			}
			set
			{
				panel1.ContextMenu = value;
				base.ContextMenu = value;
			}
		}

		public bool Selected
		{
			set
			{
				BackColor = value ? Color.SteelBlue : Color.White;
				panel1.BackColor = value ? Color.SteelBlue : Color.White;
				_contractorNameLabel.ForeColor = value ? Color.White : Color.Black;
			}
		}

		private Note _note;

		public Note Note
		{
			set
			{
				_note = value;

				const int maxLength = 64;
				var trimmedText = value.Text.Length >= maxLength ?
					value.Text.Substring(0, maxLength) + "..." : value.Text;

				_contractorNameLabel.Text = trimmedText;
			}
			get { return _note; }
		}

		public object Data
		{
			get { return Note; }
			set
			{
				if (!(value is Note))
					throw new Exception("The item should be Note type.");

				Note = (Note)value;
			}
		}

		private void OnPanelMouseDown(object sender, MouseEventArgs e)
		{
			OnMouseDown(e);
		}

		private void OnPanelMouseUp(object sender, MouseEventArgs e)
		{
			OnMouseUp(e);
		}
	}
}
